package com.dmp.frame.springboot.demo.Controller;

import com.dmp.frame.core.annotation.NotAutoResult;
import com.dmp.frame.core.exception.ResponseResult;
import com.dmp.frame.core.exception.ServiceException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.Callable;

/**
 * @author xufeng
 * @description: 测试一下包装类 和全局异常
 * @date 2022-04-20 13:47
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @PostMapping("/hello")
    public String test(){
        return "hello";
    }

    @GetMapping("/serviceEx")
    public void serviceEx(){
        throw new ServiceException(200,"zzz");
    }

    /**
     * 测试异步回调。减少主线程等待 提高并发
     * @return
     */
    @SneakyThrows
    @GetMapping(value = "index")
    public Callable<ResponseResult> GetMonthCdateRpt() {
        return () -> {
            log.info("副线程开始");
            Thread.sleep(5000);
            log.info("副线程返回");
            return ResponseResult.OK("success1");
        };
    }
}
